#ifndef LOGGER_TIME_H
#define LOGGER_TIME_H

#include "utils/time_utils.hpp"
#include <string>
#include <time.h>


namespace vpm
{
	using namespace utils;
	namespace log 
	{
		namespace detail
		{
			class LoggerTimeStamp
			{
			public:

				// Returns the current time in milliseconds.
				static long logger_time();

				// Approximate time when the program started.
				static long logger_start_time();

				// Elapsed milliseconds since StartTime()
				static long logger_elapsed_time();

				// Comparisons between time values, which can wrap around.
				static bool logger_time_is_between(long later, long middle, long earlier);

				static long logger_time_diff(long later, long earlier);
			};

			class LoggerAbsoluteTime
			{
			public:
				static char *  logger_iso8601_time(char * timeBuf, int bufLen)
				{
					const char * timeStamp = "%Y-%m-%d %H:%M:%S";
					UInt64 localTimeMillis = TimeUtils::getSystemTime();
					time_t curTime = localTimeMillis/1000000LL;
					//const tm * tm = ::gmtime(&curTime);
					size_t len = ::strftime(timeBuf, bufLen-1, timeStamp, localtime(&curTime));		
#ifdef WIN32
					_snprintf(timeBuf+len,bufLen - len,",%3ld",(long)(localTimeMillis % 1000));		
#else 
					snprintf(timeBuf+len,bufLen - len,",%3ld",(long)(localTimeMillis % 1000));		
#endif 
					return timeBuf; 
				}

                static char * logger_simple_time(char * timeBuf,int bufLen)
                {
                    const char * timeStamp = "%H:%M:%S";
                    time_t curTime = time(0);
                    size_t len = ::strftime(timeBuf, bufLen-1, timeStamp, localtime(&curTime));		
                    timeBuf[len] =0; 
                    return timeBuf;
                }

				static UInt64  logger_microsec_time()
				{
					return  TimeUtils::getSystemTime();
				}
			};
		}
	}
}

#endif // LOGGER_TIME_H

